package rest.jbpm.svg;

/**
 * Created by IntelliJ IDEA.
 * User: xEviL
 * Date: 26.10.11
 * Time: 15:06
 * To change this template use File | Settings | File Templates.
 */
class JbpmRhombElement extends JbpmCircleElement{
    public JbpmRhombElement(String _name, Integer _x, Integer _y, Integer _w, Integer _h){
        super(_name,_x,_y,(int) Math.round(1.2* _w / Math.sqrt(2)),(int) Math.round(1.2*_h / Math.sqrt(2)));
        r = ((Math.sqrt(2.0))*r);
    }

    public String draw(){
       String strokeColor = "#9f951c";
       if (active){
           strokeColor = "red";
       }
       return "<rect x=\""+(x)+"\" y=\""+(y)+"\" width=\""+w+"\" height=\""+w+"\"\n" +
               "  style=\"fill:white;stroke:"+strokeColor+";stroke-width:2;fill-opacity:1;stroke-opacity:0.9\"\n" +
               " transform=\"rotate(45,"+(x+(w/2))+","+(y+(w/2))+")\" "+
               " rx=\"5\" ry=\"5\"/>\n";
    }

    public Integer getBorderX(Integer dX, Integer dY){
        //
        Integer cX = getElCenterX();
        Integer cY = getElCenterY();

        //
        double tgA = Math.abs(((double) (dX-cX) / (double)(dY-cY)));

        return (int)Math.round(cX - (cX-dX)/Math.abs(cX-dX)*((tgA*r)/((1+tgA))));
    }

    public Integer getBorderY(Integer dX, Integer dY){
        //
        Integer cX = getElCenterX();
        Integer cY = getElCenterY();

        //
        double tgA = Math.abs(((double) (dX-cX) / (double)(dY-cY)));

        return (int)Math.round(cY - (cY-dY)/Math.abs(cY-dY)*(r/((1+tgA))));
    }
}
